﻿#region Using directives
using System;
using System.Web.UI;
using System.Text.RegularExpressions;
#endregion


namespace wLib.Objects
{
    public class wlibControlDesigner : System.Web.UI.Design.ControlDesigner
    {
        
           public override string GetDesignTimeHtml() {
               System.Reflection.Assembly l_asm = System.Reflection.Assembly.GetExecutingAssembly();
               System.IO.Stream l_css_res = l_asm.GetManifestResourceStream("wLib.Objects.ClientReferences.WTable.stylesheet.text-css.WTable.css");
               System.IO.StreamReader l_stream = new System.IO.StreamReader(l_css_res);
               string ls_css = l_stream.ReadToEnd();
   
               const string SUBSTITUTION_PATTERN = @"(<%=)\s*(WebResource\("")(?<resourceName>.+)\s*(""\)%>)";
               Regex theRegex = new Regex(SUBSTITUTION_PATTERN);
               ls_css = theRegex.Replace(ls_css, new MatchEvaluator(PerformSubstitution));
   
               return "<style>" + ls_css + "</style>" + base.GetDesignTimeHtml();
           }
   
           private string PerformSubstitution(Match m) {
               WTable thisWeightControl = (WTable)Component;
               string replacedString = m.ToString();
               replacedString = replacedString.Replace(m.Value, thisWeightControl.Page.ClientScript.GetWebResourceUrl(this.GetType(), m.Groups["resourceName"].Value));
               return replacedString;
           }
    }
}
